class Solution
{
public:
    string maximumNumber(string num, vector<int> &change)
    {
        int n = num.size();
        bool changed = false;
        for (int i = 0; i < n; ++i)
        {
            if (change[num[i] - '0'] > num[i] - '0')
            {
                num[i] = change[num[i] - '0'] + '0';
                changed = true;
            }
            else if (change[num[i] - '0'] == num[i] - '0')
            {
                continue;
            }
            else if (changed)
            {
                break;
            }
        }
        return num;
    }
};